package controllers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/httplib"
	"encoding/json"
	"xiaoercaidan/publicResources/models"
	"fmt"
)

type ShopController struct {
	beego.Controller
}


// @Title AddShop
// @Description 新增店铺
// @Param   shop     patch string   true string       "门店json"
// @router /addShop [get]
func (this *ShopController) AddShop() {

	var shopStr = this.GetString("shop")
	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/shop/add")
	req.Param("shop", shopStr)

	resp, err := req.String()

	if (err == nil) {
		var mapStr = make(map[string]interface{})

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}



// @Title GetShopList
// @Param   userId     patch string   true string       "用户ID"
// @Description 店铺列表
// @router /shopList [get]
func (this *ShopController) GetShopList() {

	userId := this.GetString("userId")
	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/shop/query")
	req.Param("userId", userId)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常" + err.Error()
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}



// @Title GetShopList
// @Param   ids     patch string   true int64       "门店ID列表，以'，'分割"
// @Description 店铺删除
// @router /shopDel [get]
func (this *ShopController) ShopDel() {

	ids := this.GetString("ids")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/shop/del")
	req.Param("ids", ids)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}




// @Title ShopUpdate
// @Param   shop     patch string   true string       "门店json"
// @Description 店铺修改
// @router /shopUpdate [get]
func (this *ShopController) ShopUpdate() {

	shop := this.GetString("shop")

	fmt.Println(shop)
	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/shop/update")
	req.Param("shop", shop)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}





// @Title GetShopList
// @Param   tableId     patch string   true int64       "桌号"
// @Param   shopId    patch string  true  int64       "店铺号"
// @Description 桌台列表
// @router /tableList [get]
func (this *ShopController) GetTableList() {

	tableId := this.GetString("tableId")
	shopId := this.GetString("shopId")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/tables/getTable")
	req.Param("tableId", tableId)
	req.Param("shopId", shopId)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}




// @Title AddTable
// @Description 新增桌台
// @Param   table     patch string   true string       "table Json"
// @router /addTable [get]
func (this *ShopController) AddTable() {

	var tableStr = this.GetString("table")
	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/tables/inserTable")
	req.Param("table", tableStr)

	resp, err := req.String()

	if (err == nil) {
		var mapStr = make(map[string]interface{})

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}



// @Title GetShopList
// @Param   tables     patch string   true string       "桌台ID列表，以'，'分割"
// @Param   shopId     patch string   true string       "门店ID列表，以'，'分割"
// @Description 桌台删除
// @router /tableDel [get]
func (this *ShopController) TableDel() {

	tables := this.GetString("tables")
	shopId := this.GetString("shopId")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/tables/tableDel")
	req.Param("tableId", tables)
	req.Param("shopId", shopId)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}




// @Title TableUpdate
// @Param   table     patch string   true string       "桌台json"
// @Description 桌台修改
// @router /tableUpdate [get]
func (this *ShopController) TableUpdate() {

	table := this.GetString("table")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/tables/tableUpdate")
	req.Param("table", table)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}





// @Title AddRing
// @Description 新增呼叫
// @Param   ring     patch string   true string       "ring Json"
// @router /addRing  [get]
func (this *ShopController) AddRing() {

	var ringStr = this.GetString("ring")
	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/add")
	req.Param("ring", ringStr)

	resp, err := req.String()

	if (err == nil) {
		var mapStr = make(map[string]interface{})

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}



// @Title TableUpdate
// @Param   ring     patch string   true string       "服务json"
// @Description 服务修改
// @router /ringUpdate [get]
func (this *ShopController) RingUpdate() {

	ring := this.GetString("ring")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/ringUpdate")
	req.Param("ring", ring)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}


// @Title GetShopList
// @Param   cateId     patch string   true int64       "分类ID"
// @Param   shopId    patch string  true  int64       "店铺号"
// @Description 呼叫列表
// @router /ringList [get]
func (this *ShopController) GetRingList() {

	tableId := this.GetString("cateId")
	shopId := this.GetString("shopId")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/ringList")
	req.Param("cateId", tableId)
	req.Param("shopId", shopId)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}





// @Title RingDel
// @Param   ids     patch string   true int64       "呼叫ID列表，以'，'分割"
// @Param shopId  patch string   true string       "店鋪ID"
// @Description 呼叫删除
// @router /ringDel [get]
func (this *ShopController) RingDel() {

	ids := this.GetString("ids")
	shopId := this.GetString("shopId")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/ringDel")
	req.Param("ids", ids)
	req.Param("shopId", shopId)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}







// @Title AddRing
// @Description 新增呼叫
// @Param   cate     patch string   true string       "ringcate Json"
// @router /addRingCate  [get]
func (this *ShopController) AddRingCate() {

	var cate = this.GetString("cate")
	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/addCate")
	req.Param("cate", cate)

	resp, err := req.String()

	if (err == nil) {
		var mapStr = make(map[string]interface{})

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}



// @Title RingCateUpdate
// @Param   ring     patch string   true string       "服务类型json"
// @Description 服务类型修改
// @router /ringCateUpdate [get]
func (this *ShopController) RingCateUpdate() {

	cate := this.GetString("cate")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/ringCateUpdate")
	req.Param("cate", cate)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}


// @Title GetRingCateList
// @Param   cateId     patch string   true int64       "分类ID"
// @Param   shopId    patch string  true  int64       "店铺号"
// @Description 呼叫类型列表
// @router /ringCateList [get]
func (this *ShopController) GetRingCateList() {

	tableId := this.GetString("cateId")
	shopId := this.GetString("shopId")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/ringCateList")
	req.Param("cateId", tableId)
	req.Param("shopId", shopId)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}





// @Title RingCateDel
// @Param   ids     patch string   true int64       "呼叫类型ID列表，以'，'分割"
// @Param shopId  patch string   true string       "店鋪ID"
// @Description 呼叫类型删除
// @router /ringCateDel [get]
func (this *ShopController) RingCateDel() {

	ids := this.GetString("ids")
	shopId := this.GetString("shopId")

	req := httplib.Get("http://" + beego.AppConfig.String("basehost") + ":" + beego.AppConfig.String("baseport") + "/v1/apis/ring/ringCateDel")
	req.Param("ids", ids)
	req.Param("shopId", shopId)

	resp, err := req.String()

	if (err == nil) {
		var mapStr map[string]interface{}

		json.Unmarshal([]byte(resp), &mapStr)

		this.Data["json"] = mapStr

	} else {
		var BaseResult = new(models.BaseResult)
		BaseResult.Code = 100
		BaseResult.Msg = "服务异常"
		this.Data["json"] = BaseResult
	}

	this.ServeJSON()

}

